package com.xyyl.patient.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;

/**
 * @projectName:xyyl-patient-web
 * @ClassName: WxPayConfiguration
 * @Description: 微信支付相关配置
 * @author chen
 * @date 2017年8月23日
 *
 */
@Configuration
public class WxPayConfiguration {
	
	@Value("#{weixin['common.appid']}")
	private String appId;

	/** 商户编号 **/
	@Value("#{weixin['pay.mchId']}")
	private String mchId;
	
	/**商户密钥 **/
	@Value("#{weixin['pay.mchKey']}")
	private String mchKey;

	@Value("#{weixin['pay.subAppId']}")
	private String subAppId;

	@Value("#{weixin['pay.subMchId']}")
	private String subMchId;

	@Value("#{weixin['pay.keyPath']}")
	private String keyPath;
	
	@Value("#{weixin['pay.tradeType']}")
	private String tradeType;

	@Bean
	public WxPayConfig payConfig() {
		WxPayConfig payConfig = new WxPayConfig();
		payConfig.setAppId(this.appId);
		payConfig.setMchId(this.mchId);
		payConfig.setMchKey(this.mchKey);
		payConfig.setKeyPath(this.keyPath);
		payConfig.setTradeType(this.tradeType);
		return payConfig;
	}

	@Bean
	public WxPayService payService() {
		WxPayService payService = new WxPayServiceImpl();
		payService.setConfig(payConfig());
		return payService;
	}
}